package com.chenfan.process.entity.po;

import com.baomidou.mybatisplus.annotation.TableName;
import com.chenfan.process.entity.dto.ApprovalTemplateReceivedDTO;
import lombok.Data;
import org.springframework.beans.BeanUtils;

/**
 * @author K
 * @date 2023/3/2 3:34 PM
 */
@TableName("template_config")
@Data
public class TemplateConfigPo {

    private Long id;
    /**
     * 模板id
     */
    private Long templateId;

    private Integer notifyFlag;

    private Boolean approvalNotify;

    private Boolean refuseNotify;

    private Boolean passNotify;

    private Boolean ccNotify;

    private Boolean remindNotify;

    private Boolean transferNotify;

    private Boolean overDueNotify;

    private Integer commitSkipped;

    private Integer sameSkipped;
    /**
     * 待办跳转url
     */
    private String messageUrl;
    /**
     * 待办跳转类型
     */
    private String jumpUrlType;
    /**
     * 自动发送待办
     */
    private Boolean autoNotify;

    private Long tenantId;

    private Long version;

    public boolean canSkip() {
        // 有对应的值, 才能跳过
        return commitSkipped != 0 || sameSkipped != 0;
    }

    public boolean startSkip() {
        return commitSkipped == 1;
    }

    public boolean historySkip() {
        return sameSkipped == 2;
    }

    public boolean continueSkip() {
        return sameSkipped == 1;
    }

    public boolean skip() {
        return historySkip() || continueSkip();
    }

    public static TemplateConfigPo ofDefault(ApprovalTemplateReceivedDTO template) {
        TemplateConfigPo templateConfigPo = new TemplateConfigPo();
        BeanUtils.copyProperties(template, templateConfigPo);
        return templateConfigPo;

    }
}
